package com.bawei.image.option

import com.bumptech.glide.load.engine.DiskCacheStrategy

/**
 * Author: Jason Zhang
 * Date: 2024/4/23
 * Desc: 图片参数对象，对外提供构建者模式
 */
class ImageOptions private constructor(
    val placeImage: Int,
    val errorImage: Int,
    val skipMemoryCache: Boolean,
    val diskCacheStrategy: DiskCacheStrategy,
    val isCircle: Boolean,
    val roundRadius: Int,
    val isGif: Boolean,
    val isStaticImg: Boolean,
    val imgSize: IntArray
){

    /**
     * 提供Builder来接收参数
     */
    companion object Builder{
        private var placeImage = 0
        private var errorImage = 0
        private var skipMemoryCache = false
        private var diskCacheStrategy = DiskCacheStrategy.NONE
        private var isCircle = false
        private var roundRadius = 0
        private var isGif = true
        private var isStaticImg = false
        private var imgSize = intArrayOf()

        fun setPlaceImage(placeImage: Int): Builder{
            this.placeImage = placeImage
            return this
        }

        fun setErrorImage(errorImage: Int): Builder{
            this.errorImage = errorImage
            return this
        }

        fun isStaticImage(isStaticImg: Boolean): Builder{
            this.isStaticImg = isStaticImg
            return this
        }

        fun isGifImage(isGif: Boolean): Builder{
            this.isGif = isGif
            return this
        }

        fun setImageSize(imgSize: IntArray): Builder{
            this.imgSize = imgSize
            return this
        }

        fun skipMemoryCache(skipMemoryCache: Boolean): Builder{
            this.skipMemoryCache = skipMemoryCache
            return this
        }

        fun setDiskCacheStrategy(diskCacheStrategy: DiskCacheStrategy): Builder{
            this.diskCacheStrategy = diskCacheStrategy
            return this
        }

        fun setCircleImage(isCircle: Boolean = true): Builder{
            this.isCircle = isCircle
            return this
        }

        fun setCommonImage(isCircle: Boolean = true): Builder{
            this.isCircle = !isCircle
            return this
        }

        fun setRoundRadius(radius: Int): Builder{
            this.roundRadius = radius
            return this
        }

        /**
         * 提供Build方法，来创建对象
         */
        fun build(): ImageOptions = ImageOptions(placeImage, errorImage, skipMemoryCache, diskCacheStrategy, isCircle, roundRadius, isGif, isStaticImg, imgSize)

    }


}